package com.syas.web.controllers;

import com.syas.common.utilities.PageListUtil;
import com.syas.service.interfaces.IGradeService;
import com.syas.web.auth.AuthPassport;
import com.syas.web.auth.AuthPassport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by weigong on 2015/12/5.
 */
@Controller
@RequestMapping(value = "/grade")
public class GradeController {

    @Autowired
    @Qualifier("GradeService")
    private IGradeService gradeService;


    @AuthPassport
    @RequestMapping(value="/gradeList", method = {RequestMethod.GET})
    public String gradeList(HttpServletRequest request, Model model){
        model.addAttribute("requestUrl", request.getServletPath());
        model.addAttribute("requestQuery", request.getQueryString());
        int pageNo = ServletRequestUtils.getIntParameter(request, PageListUtil.PAGE_NO_NAME, PageListUtil.DEFAULT_PAGE_NO);
        int pageSize = ServletRequestUtils.getIntParameter(request, PageListUtil.PAGE_SIZE_NAME, PageListUtil.DEFAULT_PAGE_SIZE);
        model.addAttribute("contentModel", gradeService.listGradePage(pageNo, pageSize));

        return "grade/gradeList";
    }

}
